Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use source-generated regex instead of runtime compilation (SYSLIB1045) #10303

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Jan 16, 2025

Fixes #10302

Description

Use GeneratedRegex attribute to allow for source-generation of regexes at compile time for improved performance.

We only use regexes in two places which could effectively be removed but for now we should at least take advantage of the highest-performing form of regular expressions on .NET.

In the PBT case, we have to use a pre-processor statement to comfort NetFX scenario, which will later need naming-styles suppression.

Note: RegexOptions.Compiled is ignored in source-generated regexes, so I've removed it.

Customer Impact

Improved performance, cleaner codebase.

Regression

No.

Testing

Local build.

Risk

While the second occurence was fixed manually because analyzer won't flag it (guess nobody thought someone is declaring regex inline with a const), the change is straightforward.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners January 16, 2025 11:31
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SYSLIB1045: Use [GeneratedRegex] for compile time source generation
1 participant